/*
 * Copyright (c) 2017 <l_iupeiyu@qq.com> All rights reserved.
 */

package cn.loveball.web.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;


@Configuration
public class ErrorPageConfig {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Bean
    public WebServerFactoryCustomizer webServerFactoryCustomizer(){
        return new MyCustomizer();
    }

    private static class MyCustomizer implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
        @Override
        public void customize(ConfigurableServletWebServerFactory factory) {
            factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/403"));
        }
    }
}
